package ai.assist.common.dto.admin;

import ai.assist.common.model.PageSearchDTO;
import ai.assist.common.utils.DateUtilsEx;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 系统日志
 *
 * @author hui
 * @email 764245287@qq.com
 * @date 2021-09-24 20:38:53
 */
@Data
@ApiModel
public class QueryLogDTO extends PageSearchDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "")
    private Long id;

    @ApiModelProperty(value = "用户id")
    private Long userId;

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "姓名")
    private String realName;

    @ApiModelProperty(value = "token")
    private String token;

    @ApiModelProperty(value = "用户操作")
    private String operation;

    @ApiModelProperty(value = "响应时间")
    private Integer time;

    @ApiModelProperty(value = "请求方法")
    private String method;

    @ApiModelProperty(value = "请求地址")
    private String url;

    @ApiModelProperty(value = "请求参数")
    private String params;

    @ApiModelProperty(value = "响应结果")
    private String response;

    @ApiModelProperty(value = "IP地址")
    private String ip;

    private List<String> createTime;

    @ApiModelProperty(hidden = true)
    private Date startTime;

    @ApiModelProperty(hidden = true)
    private Date endTime;

    public Date getStartTime() {
        if (createTime != null && !createTime.isEmpty()) {
            return DateUtilsEx.getDayStart(DateUtilsEx.parseDayByDay(createTime.get(0)));
        }
        return startTime;
    }

    public Date getEndTime() {
        if (createTime != null && !createTime.isEmpty() && createTime.size() == 2) {
            return DateUtilsEx.getDayEnd(DateUtilsEx.parseDayByDay(createTime.get(1)));
        }
        return endTime;
    }
}
